home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / winsock / ircii2-6.zip / SRC\IRCII-2.6\SOURCE\DEBUG.C < prev    next >
C/C++ Source or Header  |  1994-12-28  |  1KB  |  71 lines

  1. /*
  2.  * debug.c - generic debug routines.  Copyright (C) 1993, Matthew Green.
  3.  *
  4.  * void debug(int level,char *format, ...);    * the function to call, at
  5.  *                        * most 10 arguments to it
  6.  * int setdlevel(int level);         * set the debug level to level.
  7.  *                    * returns old level
  8.  * int getdlevel();            * returns the debug level..
  9.  * int debuglevel;            * the current level of debugging
  10.  */
  11.  
  12. #ifndef lint
  13. static    char    rcsid[] = "@(#)$Id: debug.c,v 1.5 1994/10/14 23:12:18 mrg Stab $";
  14. #endif
  15.  
  16. #include "config.h"        /* This is where DEBUG is defined or not */
  17.  
  18. #ifdef DEBUG
  19. # include <stdio.h>
  20. # include "debug.h"
  21. # ifdef USE_STDARG_H
  22. #  include <stdarg.h>
  23. # endif
  24.  
  25. int    debuglevel = 0;
  26.  
  27. int    setdlevel(level)
  28. int    level;
  29. {
  30.     int    oldlevel = debuglevel;
  31.  
  32.     debuglevel = level;
  33.     return oldlevel;
  34. }
  35.  
  36. int    getdlevel()
  37. {
  38.     return debuglevel;
  39. }
  40.  
  41. void
  42. #ifdef USE_STDARG_H
  43. debug(int level, char *format, ...)
  44. #else
  45. debug(level, format, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9)
  46.     int    level;
  47.     char    *format;
  48.     char    *arg0, *arg1, *arg2, *arg3, *arg4,
  49.         *arg5, *arg6, *arg7, *arg8, *arg9;
  50. #endif
  51. {
  52.     char    buffer[2048];
  53. #ifdef USE_STDARG_H
  54.     va_list vlist;
  55.  
  56.     va_start(vlist, format);
  57. #endif
  58.  
  59.     if (!debuglevel || level > debuglevel)
  60.         return;
  61.  
  62. #ifdef USE_STDARG_H
  63.     vfprintf(stderr, format, vlist);
  64. #else
  65.     fprintf(stderr, format, arg0, arg1, arg2, arg3, arg4,
  66.                 arg5, arg6, arg7, arg8, arg9);
  67. #endif
  68.     fputc('\n', stderr);
  69. }
  70. #endif /* DEBUG */
  71.